﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TestRootBaseData.Service.Model;

namespace TestRootBaseData
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Service.ServiceManager _Manager;

        public Service.ServiceManager Manager1
        {
            get 
            {
                if (_Manager == null)
                    _Manager = new Service.ServiceManager();
                return _Manager;
            }
            //set { _Manager = value; }
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //populate
            this.radGridView1.ItemsSource = Manager1.Populate();

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.radGridView1.ItemsSource = Manager1.GetPeople();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            //clear
            Manager1.ClearPeople();

        }

        Person _selectedParent;

        Person _selectedChild;

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            //select parent
           _selectedParent= (Person)radGridView1.SelectedItem;
           radNumericUpDown1.Value = _selectedParent.EntityId;
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            _selectedChild = (Person)radGridView1.SelectedItem;
            radNumericUpDown2.Value = _selectedChild.EntityId;

        }


        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (_selectedChild != null && _selectedParent != null)
            {
                if (_selectedChild.EntityId != _selectedParent.EntityId)
                {
                   _selectedChild =   Manager1.MakeChild(_selectedParent, _selectedChild);
                   radGridView1.ItemsSource = _selectedChild;
                }
            }
        }
    }
}
